// view/my/sqdc/sqdc.js
let app = getApp()
let yuming = app.globalData.yuming
const request = require('../../config/request');
Page({
    ...request,
    /**
     * 页面的初始数据
     */
    data: {
        yuming: yuming,
        heights: '',
        title: "申请点餐码",
        isbo: false,
        yearlist: ['1', '2', '3', '4'],
        yearindex: 0,
        mon: '0',
        xinxi: '',
        cheng: '',
        maskFlag: true,
        focus: false,
        Length: 6, //输入框个数  
        isFocus: false, //聚焦  
        Value: "", //输入的内容  
        ispassword: true, //是否密文显示 true为密文， false为明文。
    },
    list() {
        this.myRequest(yuming + 'Besall/findCityConfig', {
            shopId: wx.getStorageSync('shopId')
        }, "POST").then(res => {
            this.setData({
                xinxi: res.data.data,
                mon: res.data.data.orderFee,
                cheng: res.data.data.orderFee
            })
        })
    },
    // 遮罩层视频切换
    shipin() {
        this.setData({
            isbo: !this.data.isbo
        })
        this.bofang()
    },
    // 点击播放
    bofang() {
        this.videoContext = wx.createVideoContext('myVideo')
        this.videoContext.play()
    },
    // 服务费说明
    shuo() {
        wx.navigateTo({
            url: '/page_zhu/xieyi/xieyi?title=服务费用说明&state=dcmfwsm',
        })
    },
    // 选择年
    bindyear(e) {
        var index = e.detail.value
        var shu = this.data.yearlist[index]
        this.setData({
            yearindex: index,
            mon: this.data.cheng * shu
        })
    },
    backs() {
        wx.navigateBack({
            delta: 1
        })
    },
    // 支付
    zhifu() {
        this.myRequest(yuming + 'shop/shopApplyForFood', {
            shopId: wx.getStorageSync('shopId'),
            price: this.data.mon,
            years: Number(this.data.yearindex) + 1
        }, "POST").then(res => {
            this.setData({
                bianhao: res.data.out_trade_no,
                maskFlag: false
            })
            console.log(this.data.bianhao)
        })
        // wx.navigateTo({
        //   url: '/my_dian/dianindex/dianindex',
        // })
        // wx.showToast({
        //   title: '暂未开通',
        //   icon:'none'
        // })
    },
    //   输入支付密码
    password_input: function (e) {
        var that = this;
        console.log(e.detail.value);
        var inputValue = e.detail.value;
        that.setData({
            Value: inputValue,
            isFocus: true,
        })
        console.log(that.data.value)
    },

    Tap() {
        var that = this;
        that.setData({
            isFocus: true,
        })
    },

    getFocus: function () {
        this.setData({
            focus: !this.data.focus
        })
    },
    cancel() {
        this.setData({
            Value: '',
            maskFlag: true
        })
    },
    close(){
        this.setData({
            maskFlag: true
        })
    },
    sure() {
        if (this.data.Value != '123456') {
            wx.showToast({
                title: '密码错误，请重新输入',
                icon: 'none'
            })
        } else {
            this.fukuan()
        }
    },
    fukuan() {
        this.myRequest(yuming + 'Notify/pay_notify', {
            out_trade_no: this.data.bianhao
        }, "POST").then(res => {
            wx.showToast({
                title: res.data.msg,
                icon: 'none'
            })
            this.setData({
                maskFlag:true,
                Value:''
            })
            setTimeout(function () {
                wx.navigateTo({
                    url: '/my_dian/dianindex/dianindex',
                })
            }, 1500);
           
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            heights: wx.getMenuButtonBoundingClientRect().top + 5,
            title: options.title
        })
        this.list()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },
})